#  This file is part of FlickFleck.
#  Copyright (C) 2008 Jyke Tapani Jokinen
#
#    FlickFleck is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FlickFleck is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with FlickFleck.  If not, see <http://www.gnu.org/licenses/>.
#
import config
import tkMessageBox
import sys
import wins
import mainwin
import i18n

#-----------------------------------------------------------------
# show error message and close the application
#
def ERR( str ):
    tkMessageBox.showerror(i18n.name['apperror'], 
                           str + '\n' + i18n.name['appclose'] )
    sys.exit()

#-----------------------------------------------------------------
# all done. this version closes application after this
#
def Ready():
    tkMessageBox.showinfo(config.TITLE, i18n.name['finished'] +
                          '\n' + i18n.name['appclose'] )
    sys.exit()
    
#-----------------------------------------------------------------
def status( str ):
    wins.main.status( str )

#-----------------------------------------------------------------
# called at program startup
# creates all windows
#
def init():
    wins.root = Pmw.initialise( fontScheme = 'pmw1' )
    wins.root.withdraw()
    if sys.platform == 'darwin' and hasattr(sys, 'frozen'):
        wins.root.tk.call('console', 'hide')
    wins.root.title( config.TITLE )

    if sys.platform == 'win32':
        wins.root.iconbitmap('flickfleck.ico')
    elif sys.platform == 'darwin':
        grey="#CCCCCC"
        wins.root.config(background=grey, highlightbackground=grey)
#        wins.root.option_add( "*background", grey )
#        wins.root.option_add( "*activebackground", grey )
#        wins.root.option_add( "*highlightbackground", grey )
#        wins.root.option_add( "*insertBackground", grey )
#        wins.root.option_add( "*selectBackground", grey )
	wins.root.tk_setPalette( grey )
    else:
	pass
        #wins.root.iconbitmap('flickfleck.xbm')

    wins.main = mainwin.FlickFleck(wins.root)
    wins.root.deiconify()

#-----------------------------------------------------------------
def start():
    wins.root.mainloop()

#-----------------------------------------------------------------
# engine calls this in file operations loops to check if user
# wants to cancel
#
def checkStop():
    wins.root.update()
    if wins.requestStop:
        ERR("Stopped by the User")

